package com.gin.kotlin.no_gay_alliance.provider.ngaphp

import com.gin.nga.main.NgaApi
import com.gin.nga.response.user.BlockConfigBody
import java.lang.ref.WeakReference

class BlockConfigProvider private constructor() :
    AbstractCachedDataProvider<Nothing, BlockConfigBody, BlockConfigBody>(TYPE_FACTORY.constructType(BlockConfigBody::class.java)) {
    override val dir = "BLOCK_CONFIG"

    override fun obtainRelativePath(userId: Long, params: Nothing?) = "${userId}.json"

    override fun requestMethod(ngaApi: NgaApi, params: Nothing?) = ngaApi.accountApi.blockConfigGet()

    override fun transform(rawData: BlockConfigBody) = rawData

    companion object {
        private var instance: WeakReference<BlockConfigProvider> = WeakReference(BlockConfigProvider())
        fun getInstance(): BlockConfigProvider = instance.get() ?: BlockConfigProvider().also { instance = WeakReference(it) }
    }
}